package com.classops.demo

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import coil3.load
import com.classops.demo.bean.UserResponse
import com.classops.demo.databinding.ActivityMainBinding
import com.therouter.TheRouter
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import org.koin.androidx.viewmodel.ext.android.viewModel

class MainActivity : AppCompatActivity() {

    private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) }

    private val viewModel by viewModel<MainViewModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

//        binding.ivIcon.load(R.mipmap.ic_launcher)
        binding.ivIcon.load("https://avatars.githubusercontent.com/u/15867703?v=4")
        // 测试
        binding.btnTest.setOnClickListener {
            viewModel.test()
            TheRouter.build("/detail")
                .navigation()
        }

//        Json.encodeToString(UserResponse(1, "test"))
//        val json = buildJsonObject {
//            put("12", 1)
//        }

    }
}